import { http } from "@/utils/http";
import { baseUrlApi } from "@/api/utils";
import { message } from "@/utils/message";
type Result = {
  current_page: number;
  result?: any;
  per_page?: number;
  total?: number;
};
type ResultDelete = {
  code: number;
  message: string;
};
type ResultCreate = {
  code: number;
  message: string;
};
type Show = {
  code: number;
  message: string;
  result?: any;
};

/** 项目列表 */
export const projectListApi = (params?: object) => {
  return http.request<Result>("get", baseUrlApi + "/project/list", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
/** 项目列表 */
export const tallyListApi = (params?: object) => {
  return http.request<Result>("get", baseUrlApi + "/statistic/project/list", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 添加项目 */
export const projectStoreApi = (data?: object) => {
  return http.request<ResultCreate>("post", baseUrlApi + "/project/store", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 编辑项目 */
export const projectUpdateApi = (data?: object) => {
  return http.request<ResultCreate>("put", baseUrlApi + "/project/update", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 详情项目 */
export const projectShowApi = (params?: object) => {
  return http.request<ResultCreate>("get", baseUrlApi + "/project/show", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 删除项目 */
export const projectDeleteApi = (data?: object) => {
  return http.request<ResultDelete>("delete", baseUrlApi + "/project/delete", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 选择项目 */
export const projectSelectApi = (params?: object) => {
  return http.request<Show>("get", baseUrlApi + "/project/select", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
/** 任务统计 */
export const tasktallyApi = (params?: object) => {
  return http.request<Result>("get", baseUrlApi + "/statistic/project/taskTally", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
/** 用户逾期统计 */
export const usertallyApi = (params?: object) => {
  return http.request<Result>("get", baseUrlApi + "/statistic/project/userTally", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 任务类型 */
export const typeSelect = (params?: object) => {
  return http.request<Result>("get", baseUrlApi + "/task/typeSelect", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 当年月项目统计 */
export const getProjectMonthly = (params?: object) => {
  return http.request<Result>("get", baseUrlApi + "/statistic/project/getProjectMonthly", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 项目经济统计 */
export const getProjectMoneyApi = (params?: object) => {
  return http.request<Result>("get", baseUrlApi + "/statistic/project/getProjectMoney", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 项目经济统计 */
export const getTaskMoneyApi = (params?: object) => {
  return http.request<Result>("get", baseUrlApi + "/statistic/project/getTaskMoney", {
    params
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 项目状态更新 */
export const projectUpdateStatusApi = (data?: object) => {
  return http.request<ResultCreate>("put", baseUrlApi + "/project/updateStatus", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};

/** 纠正项目数据 */
export const projectReplacentApi = (data?: object) => {
  return http.request<ResultCreate>("post", baseUrlApi + "/project/replacent", {
    data
  }).catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
